package com.hpu.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.hpu.entity.Menu;
import com.hpu.util.DBhelp;
import com.hpu.util.RowMapper;

public class MenuDao {

	private DBhelp<Menu> dbMenu = new DBhelp<Menu>();
	
	public List<Menu> findAllMenus(){
		String sql = "select id,dish_name,category_id,price,pic from t_menu";
		return dbMenu.executeQueryForList(sql, new MenuRowMapper());
	}
	public Menu findMenuById(int id){
		String sql = "select id,dish_name,category_id,price,pic from t_menu where id = ?";
		return dbMenu.executeQueryForObject(sql, new MenuRowMapper(), id);
	}
	
	
	
	
	private class MenuRowMapper implements RowMapper<Menu>{
		public Menu mapperRow(ResultSet rs) throws SQLException {
			Menu menu = new Menu();
			menu.setCategory_id(rs.getInt("category_id"));
			menu.setDish_name(rs.getString("dish_name"));
			menu.setCont("cont");
			menu.setId(rs.getInt("id"));
			menu.setPrice(rs.getFloat("price"));
			menu.setPic(rs.getString("pic"));
			return menu;
		}
		
		
		
	}

	public List<Menu> findAllMenusByCategory(String category) {
		String sql="select id,dish_name,category_id,price,pic,cont from t_menu where category_id=?";
		return dbMenu.executeQueryForList(sql, new MenuRowMapper(),category);
	}
	
}
